package org.scohen.juploadr.uploadapi.flickrrest.urls;

import java.net.URL;
import java.util.SortedMap;
import java.util.TreeMap;

import org.scohen.juploadr.uploadapi.ProtocolException;
import org.scohen.juploadr.uploadapi.flickrrest.DefaultFlickrHandler;
import org.scohen.juploadr.uploadapi.flickrrest.FlickrMethod;
import org.scohen.juploadr.uploadapi.flickrrest.RestFlickrApi;
import org.scohen.juploadr.uploadapi.flickrrest.UserNotFoundException;

public class GetUserPhotos extends FlickrMethod {
    private URL url;

    public SortedMap<String, String> getParams() {
        TreeMap<String, String> params = new TreeMap<String, String>();
        params.put("api_key", RestFlickrApi.FLICKR_API_KEY);
        params.put("method", "flickr.urls.getUserPhotos");
        return params;
    }

    public DefaultFlickrHandler getResponseHandler() {

        return new GetUserPhotosHandler(this);
    }

    public boolean isAuthorized() {
        return true;
    }

    void setURL(URL url) {
        this.url = url;
    }

    public URL getURL() {
        return url;
    }

    @Override
    protected ProtocolException buildProtocolException(int errorCode) {
        switch (errorCode) {
        case 1:
            return new UserNotFoundException();
        case 2:
            return new NoUserSpecifiedException();
        default:
            return null;
        }
    }

}
